package mis.ds.ps.controller;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Result {

	private String entity;

	private Map<String, LinkedList<Object>> avpMap;

	public Result(String entity) {
		super();
		this.setEntity(entity);
		this.avpMap = new LinkedHashMap<String, LinkedList<Object>>();

	}

	public boolean addResult(String key, Object result) {

		if (key != null && result != null) {

			LinkedList<Object> valueList = null;

			if (avpMap.get(key) != null) {
				valueList = avpMap.get(key);
			} else {
				valueList = new LinkedList<Object>();
			}

			valueList.add(result);
			avpMap.put(key, valueList);

			return true;
		}
		return false;
	}

	public boolean contains(Object result) {

		for (Iterator<LinkedList<Object>> it = avpMap.values().iterator(); it.hasNext();) {
			LinkedList<Object> valueList = it.next();

			for (Object object : valueList) {
				if (object.equals(result)) {
					return true;
				}
			}

		}

		return false;
	}

	public void setEntity(String entity) {
		this.entity = entity;
	}

	public String getEntity() {
		return entity;
	}

	public int getSize() {
		return avpMap.size();
	}

	public Map<String, LinkedList<Object>> getValueMap() {
		return avpMap;
	}

	public LinkedList<Object> getValueList(String key) {
		return avpMap.get(key);
	}

	@Override
	public String toString() {
		return "Result [entity=" + entity + ", avpMap=" + avpMap + "]";
	}

}
